import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const router = new Router({
    mode: "history",
    routes: [
        {
            path: '/',
            name: 'home',
            component: ()=> import('../views/MallHome'),
            redirect: '/index',
            children: [
                {
                    path: '/index',
                    name: 'index',
                    meta: {
                        title: '小米商城 - Xiaomi 13、Redmi K60、MIX FOLD 2，小米电视官方网站'
                    },
                    component: ()=> import('../views/MallIndex'),
                },
                {
                    path: '/detail/:id',
                    name: 'detail',
                    component: ()=> import('../views/MallDetail'),
                },
                {
                    path: '/product/:id',
                    name: 'product',
                    component: ()=> import('../views/MallProduct'),
                }
            ]
        },
        {
            path: '/order',
            name: 'order',
            redirect: '/index',
            component: ()=> import('../views/MallOrder'),
            children: [
                {
                    path: 'confirm',
                    name: 'orderConfirm',
                    component: ()=> import('../views/MallOrderConfirm'),
                },
                {
                    path: 'pay',
                    name: 'orderPay',
                    component: ()=> import('../views/MallOrderPay'),
                },
            ]
        },
        {
            path: '/cart',
            name: 'cart',
            component: ()=> import('../views/MallCart')
        },
        {
            path: '/login',
            meta: {
                title: '小米帐号 - 登录'
            },
            name: 'login',
            component: ()=> import('../views/MallLogin')
        }
    ]
})

router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title
    }
    next()
})

export default router
